﻿using System.Xml;

namespace Jayden.Dll.Sc2.Descriptions
{
	public class ActionDescription : Description
	{

		public delegate void ExecuteDelegate(GameState state);

		private EntityDescription m_Entity;
		protected string m_IconId = null;

		protected ActionDescription(EntityDescription entity, string id, string name = null, string iconId = null)
			: base(id, name)
		{
			m_Entity = entity;
			m_IconId = iconId;
		}
		public ActionDescription(EntityDescription entity, XmlNode node)
			: base(node)
		{
			XmlAttribute icon = node.Attributes["icon"];
			if (icon != null)
				m_IconId = icon.Value;
			m_Entity = entity;
		}

		public EntityDescription Entity { get { return m_Entity; } }
		public virtual string IconId { get { return m_IconId ?? Entity.IconId; } }

		public virtual bool IsAccessible(GameState state) { return true; }
		public virtual bool IsExecutable(GameState state) { return true; }
		public virtual void Execute(GameState state)
		{
			m_Entity.OnExecuteAction(this, state);
		}
	}
}
